from datetime import datetime
from tabnanny import verbose
from django.db import models
from django.contrib.auth.models import User

# Create your here.

class ProductType(models.Model): # 公司项目类型

    product_type = models.CharField(max_length=50)

    def __str__(self) -> str:
        return self.product_type

    class Meta:

        verbose_name = "公司项目类型"
        verbose_name_plural = "公司项目类型"



class Product(models.Model): # 项目

    STATUS = (
        (0, '撤销'),
        (1, '等待'),
        (2, '进行中'),
        (3, '完成'),
    )

    product_type = models.ForeignKey(ProductType, on_delete=models.PROTECT, verbose_name='项目类型')
    
    product = models.CharField('项目名称', max_length=50, unique=True)

    product_code = models.CharField('项目代码', max_length=50, unique=True)

    master = models.ForeignKey(User, on_delete=models.PROTECT, verbose_name='项目负责人')

    goal = models.TextField('项目目标', default='', blank=True)

    pub_date = models.DateTimeField('发布日期', default=datetime.now())  # 项目生成日期

    start_date = models.DateTimeField('项目开始时间', default=datetime.now())

    end_date = models.DateTimeField('项目结束时间（预计）')

    completion_date = models.DateTimeField('项目实现结束时间', null=True, default='', blank=True) #实际完成时间

    operation = models.IntegerField('项目状态', default=1, choices=STATUS)  # 0 为撤销 1 为等待 2为进行中 3为完成

    def __str__(self) -> str:
        return self.product_type.product_type + ':' + self.product

    class Meta:

        verbose_name = "项目"
        verbose_name_plural = "项目"


class ProductBacklog(models.Model): # 项目待办

    STATUS = (
        (0, '撤销'),
        (1, '等待'),
        (2, '进行中'),
        (3, '完成'),
    )

    product = models.ForeignKey(Product, on_delete=models.PROTECT, verbose_name='分项所属总项')

    responsible = models.ForeignKey(User, on_delete=models.PROTECT, verbose_name='分项负责人') # 负责人

    product_backlog = models.CharField('分项名称', max_length=50)

    goal = models.TextField('分项目标', default='', blank=True)

    start_date = models.DateTimeField('分项开始时间', default=datetime.now())

    end_date = models.DateTimeField('分项结束时间（预计）')

    completion_date = models.DateTimeField('实际完成时间', null=True, default='', blank=True) #实际完成时间

    operation = models.IntegerField('分项状态', default=1, choices=STATUS)  # 0 为撤销 1 为等待 2为进行中 3为完成

    def __str__(self) -> str:
        return self.product.product + ':' + self.product_backlog

    class Meta:

        verbose_name = "项目待办"
        verbose_name_plural = "项目待办"

class SprintBacklog(models.Model): # 冲刺
    
    STATUS = (
        (0, '撤销'),
        (1, '等待'),
        (2, '进行中'),
        (3, '完成'),
    )

    product_backlog = models.ForeignKey(ProductBacklog, on_delete=models.PROTECT, verbose_name='所属分项')

    sprint_backlog = models.CharField('冲刺名称', max_length=100)

    goal = models.TextField('冲刺目标', default='', blank=True)

    start_date = models.DateTimeField('开始时间', default=datetime.now())

    end_date = models.DateTimeField('结束时间（预计）')

    completion_date = models.DateTimeField('实际结束时间', null=True, default='', blank=True) #实际完成时间

    operation = models.IntegerField('冲刺状态', default=1, choices=STATUS)  # 0 为撤销 1 为等待 2为进行中 3为完成

    def __str__(self) -> str:
        return self.product_backlog.product.product + ':' + self.product_backlog.product_backlog + ':' + self.sprint_backlog

    
    class Meta:

        verbose_name = "项目待办冲刺"
        verbose_name_plural = "项目待办冲刺"




